<include file="Public:header" />
<div class="container main"> <include file="Public:left" />
  <div class="w790">
  <script>
	  //插入html内容到template编辑框
	  function insertHtml(html){
		  UE.getEditor('template').execCommand('insertHtml', html);
	  }
  	//通过弹出窗口的形式打开添加字段信息页面
	function openupedit(url){
		art.dialog.open(url, {width: 600, height: 400,lock:true,title:'字段编辑', ok:			    	function(){
			var d = this.iframe.contentWindow.document;
			var img_list = new Array();
			$(d).find("input[name='mimg_url[]']").each(function(index, element) {
                img_list.push("'"+$(this).val()+"'");
            });
			var imgcate_id = $(d).find("#imgcate_id").val();
			$.post('{:U('insert')}',{img_list:img_list.toString(),imgcate_id:imgcate_id},function(data){
				if(data=='OK'){
						window.location.href = url;
					}
			});
			return false;
		}});
	}
  
  	function uploaded(path){
		$("#img_url").attr("src",'__PUBLIC__'+path);
		$("input[name='img_url']").val(path);
	}
	
	function del_img(){
		if(confirm('您确定要删除图片吗?')){
			var file=$("input[name='img_url']").val();
			$.post("{:U('delImgBypath')}",{'path':file},function(data){
				$("input[name='img_url']").val('');
				$("#img_url").attr('src','');
			});
		}else{
			return false;
		}
	}
	//删除图组图片
	function mdel_img(path){
		$('#img_list div img').each(function(index, element) {
			$.post("{:U('delImgBypath')}",{'path':path},function(data){
				
					
					$('#img_list div').each(function(index, element) {
                        if($(this).attr('url')==path){
							$(this).remove();
						}
                    });
					
					$('#picmsg input').each(function(index, element) {
                        if($(this).val()==path){
							$(this).remove();
						}
                    });
			
			});
		});
	}
	
	
	$(document).ready(function(e) {
    $('#control li').each(function(index, element) {
        $(this).click(function(e) {
			$(this).parent().find('li').removeClass('cur');
            $(this).addClass('cur');
			$('.setting_table').hide();
			$('.setting_table').eq(index).show();
        });
    });
});
function relateListadd(id,title,cate_name){
	//防止重复
	if(!$('#relateList input[value="'+id+'"]').length>0){
		$('<li>'+id+'<input type="hidden" name="relateid[]" value="'+id+'" /><input type="hidden" name="relatecate_name[]" value="'+cate_name+'" /><input size="70" type="text" name="relatetitle[]" value="'+title+'" /><a href="javascript:void(0);" onclick="after(this);">上</a><a href="javascript:void(0);" onclick="append(this);">下</a><span id="relateListdel'+id+'" class="relateListdel" onclick="relateListdel('+id+');">×</span></li>').appendTo('#relateList');
	}
}
function after(e){
	$(e).parent('li').after($(e).parent('li').prev());
}
function append(e){
	$(e).parent('li').next().after($(e).parent('li'));
}
function relateListdel(id){
	$('#relateListdel'+id).parent('li').remove();
}
function showRelate(){
			    art.dialog.open('{:U('News/relate')}', {width: 600, height: 400, ok:function(){
					
				}});
			}





    // 在光标处插入字符串
    // myField    文本框对象
    // 要插入的值
    function insertAtCursor(myField, myValue) 
    {
        //IE support
        if (document.selection) 
        {
            myField.focus();
            sel            = document.selection.createRange();
            sel.text    = myValue;
            sel.select();
        }
        //MOZILLA/NETSCAPE support
        else if (myField.selectionStart || myField.selectionStart == '0') 
        {
            var startPos    = myField.selectionStart;
            var endPos        = myField.selectionEnd;
            // save scrollTop before insert
            var restoreTop    = myField.scrollTop;
            myField.value    = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
            if (restoreTop > 0)
            {
                // restore previous scrollTop
                myField.scrollTop = restoreTop;
            }
            myField.focus();
            myField.selectionStart    = startPos + myValue.length;
            myField.selectionEnd    = startPos + myValue.length;
        } else {
            myField.value += myValue;
            myField.focus();
        }
    }

</script>
  <style>
  	#replyList ul li{margin-top:5px; background:#eee; padding:8px; width:700px;}
	.delnews{display:block; width:30px; font-size:20px; height:30px; border-radius:15px; background:#f00; color:#fff; line-height:30px; text-align:center;}
	.setInte input{margin-bottom:5px;}
	#control{border-bottom:1px solid #558fca; margin-bottom:10px;}
		#control li{float:left; height:40px; line-height:40px; border:1px solid #558fca; border-bottom:none;}
		#control li a{padding:0px 8px;}
		#control li.cur{background:#558fca;}
		#control li.cur a{color:#fff; font-weight:bold;}
		.relateListdel{display:inline-block; width:20px; height:20px; text-align:center; font-size:18px; cursor:default;}
  </style>
  <div class="h"><a href="{:U('index')}" class="btn btn-info"><i class="glyphicon glyphicon-circle-arrow-left"></i> 返回表单列表</a> </div>
  <form class="checkoutform form-horizontal" action="{:U('update')}" method="post">
    <div class="table_ container">
      <input type="hidden" name="id" value="{$info.id}" >
      <div class="setting_table">
        <div class="form-group">
          <label class="col-sm-2 control-label">表单名称</label>
          <div class="col-sm-10">
            <input datatype="*" class="form-control" value="{$form.name}" name="name" type="text" id="title" size="70" >
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">关联积分规则</label>
          <div class="col-sm-10">
            <html:listselect class="btn btn-sm btn-success" selected="form['rule']" name="rule" multiple="1" url="{:U('Integral_rule/select')}" title="选择积分规则" />
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">审核人</label>
          <div class="col-sm-10">
            <html:listselect class="btn btn-sm btn-success" selected="form['approver']" name="member" multiple="1" url="{:U('Member/select')}" title="选择审核人" />
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">规则操作方式</label>
          <div class="col-sm-10"> 
            
            <!-- 0用户领取，1自动分发（此时需要周期） -->
            
            <label class="checkbox-inline"> <input name="rulecheck" type="radio" value="0" 
              
              <eq name="info['rulecheck']" value="0">checked="checked"</eq>
              />
              单选</label>
            <label class="checkbox-inline"> <input name="rulecheck" type="radio" value="1" 
              
              <eq name="info['rulecheck']" value="1">checked="checked"</eq>
              />
              多选</label>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">分发方式</label>
          <div class="col-sm-10"> 
            
            <!-- 0用户领取，1自动分发（此时需要周期） -->
            
            <label class="checkbox-inline"> <input name="handtype" type="radio" value="0" 
              
              <eq name="info['handtype']" value="0">checked="checked"</eq>
              />
              用户领取</label>
            <label class="checkbox-inline"> <input name="handtype" type="radio" value="1" 
              
              <eq name="info['handtype']" value="1">checked="checked"</eq>
              />
              自动分发</label>
          </div>
        </div>
        
        
        
        
        <div class="form-group">
          <label class="col-sm-2 control-label">表格分类</label>
          <div class="col-sm-10"> 
            <select class="form-control" datatype="*" name="formcategory_id" id="formcategory_id">
          <option value="">请选择</option>
          <volist name="formcategory" id="vo">
           
            <option <eq name="vo['id']" value="$form['formcategory_id']">selected="selected"</eq> value="{$vo.id}">{$vo.name}</option>
          </volist>
        </select>
          </div>
        </div>
        
        
        
        
        
        
        
        <div class="form-group setInte">
          <label class="col-sm-2 control-label">积分因数</label>
          <div class="col-sm-10">
          <input id="{$vo.id}" onclick="insertAtCursor(document.getElementById('formula'),'approver');" value="审批人" class="btn btn-info btn-sm" type="button"/>
          
          
          
          <input id="{$vo.id}" onclick="insertAtCursor(document.getElementById('formula'),'approver_id');" value="默认审批人" class="btn btn-info btn-sm" type="button"/>
          
          
          <input id="{$vo.id}" onclick="insertAtCursor(document.getElementById('formula'),'proposer');" value="提交人" class="btn btn-info btn-sm" type="button"/>
          
          
          <input id="{$vo.id}" onclick="insertAtCursor(document.getElementById('formula'),'{<?php echo '$rule';?>}');" value="系统积分规则" class="btn btn-info btn-sm" type="button"/>
          
          <!-- 积分类型 -->
          
          <volist name="InteType" id="vo">
              <input id="{$vo.id}" onclick="insertAtCursor(document.getElementById('formula'),'{$vo.typename}');" value="{$vo.remark}" class="btn btn-info btn-sm" type="button"/>&nbsp;
          </volist>
          <!-- 积分类型结束  -->
            <volist name="list" id="vo">
            
            
            

            
            
              <input id="{$vo.id}" onclick="insertAtCursor(document.getElementById('formula'),'<?php echo (in_array($vo['f_type'], array(9,10,11,12))?$vo['f_name'].'_id':'{'.'$'.$vo['f_name'].'}');?>');" value="{$vo.name}" class="btn btn-info btn-sm" type="button"/>
              &nbsp; </volist>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">积分公式</label>
          <div class="col-sm-10">
            <p>运算符（格式：人员:积分类型="公式"）</p>
            <textarea name="formula" id="formula" class="form-control" style="height:200px;">{$info.formula}</textarea>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">表单字段</label>
          <div class="col-sm-10">
            <volist name="list" id="vo">
              <input id="{$vo.id}" class="btn btn-info btn-sm" onclick="insertHtml('{<?php echo '$field_'.$vo['id'];?>}');" value="{$vo.id}-{$vo.name}" type="button"/>
              &nbsp; </volist>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-2 control-label">表单</label>
          <div class="col-sm-10">
            <html:editor id="template" name="template" type="UEDIT" style="height:400px; width:100%;">{$form.template}</html:editor>
          </div>
        </div>
      </div>
    </div>
    </div>
    <div class="pages">
      <button type="submit" class="btn btn-success">保存</button>
    </div>
  </form>
</div>
<div class="clear"></div>
</div>
<include file="Public:footer" />